package com.example.controller;

import com.example.pojo.ArticleCategory;
import com.example.pojo.Result;
import com.example.service.ArticleCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/aricleCategories")
public class ArticleCategoryController {
    @Autowired
    private ArticleCategoryService articleCategoryService;
    @GetMapping
    public Result list(){
        log.info("查询全部数据");
       List<ArticleCategory> articleCategoryList= articleCategoryService.findAll();
       return Result.success(articleCategoryList);
    }
    //传参一致则省略@RequestParam
    @DeleteMapping
    public Result delet(Integer id){
        log.info("根据ID删除"+id);
        articleCategoryService.deleteById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody ArticleCategory articleCategory){
        log.info("新增："+articleCategory);
        articleCategoryService.insert(articleCategory);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable  Integer id){
        log.info("根据ID查询"+id);
        ArticleCategory articleCategory= articleCategoryService.getById(id);
        return Result.success(articleCategory);
    }
    @PutMapping
    public Result update(@RequestBody ArticleCategory articleCategory){
        log.info("修改"+articleCategory);
        articleCategoryService.update(articleCategory);
        return Result.success();
    }
}
